﻿@model HWmanagementClient.Models.TeacherHomeworks
@{
    ViewBag.Title = "Tárgyak";
}
<script type="text/javascript">
    $(function () {
        $("#studentcourses").accordion();
        $("a.buttonclass").button();

        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "/Teacher/GetTeachers2",
            dataType: "json",
            async: false
        })
			.done(function (msg) {
			    $('#addt').autocomplete({
			        source: msg
			    });
			});
    });

    var markup = '<tr id="trashable${Neptun}">' +
                        '<td>' +
                        '<strong><em>${Name}</em> (${Neptun})</strong>' +
                        '</td>' +
                        '<td>' +
                        '<a href="#" class="buttonclass" style="color: white;" onclick="deltea(\'${Neptun}\');">Törlés</a>' +
                        '</td>' +
                    '</tr>';

    function manage(nept) {
        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "/Teacher/GetSubTeach/"+nept,
            dataType: "json",
            async: false
        })
			.done(function (msg) {
			    var hw = msg.users;
			    //alert(hw);
			    $("tr[id*='trashable']").remove();
			    $.template("hw_templ", markup);
			    $("#hwcontainer").before($.tmpl("hw_templ", hw));
			    //$.tmpl("hw_templ", hw).appendTo("#hwcontainer");
			    $("a.buttonclass").button();
			    $("#addt").show();
			    $("#addtb").show();
			});
			$("#subhidden").val(nept);
    }

    function deltea(nept) {
        //$("#trashable"+nept).hide();
        $.ajax({
            type: "POST",
            url: "/Teacher/DeleteTeacher/",
            data: { subject: $("#subhidden").val(), user: nept },
            async: false
        })
			.done(function (msg) {
			    if (msg == true) {
			        location.reload();
			    }
			    else {
			        alert("A törlés nem sikerült");
			    }
			});
    }


    function addtea() {
        $.ajax({
            type: "POST",
            url: "/Teacher/AddTeacher/",
            data: { subject: $("#subhidden").val(), user: $("#addt").val() },
            async: false
        })
			.done(function (msg) {
			    if (msg == true) {
			        location.reload();
			    }
			    else {
			        alert("A hozzáadás nem sikerült");
			    }
			});
    }


</script>
<h2>
    Tárgy menedzsment</h2>
    [ @Html.ActionLink("Naplók", "Logs", "Teacher") ]<br /><br />
<input type="hidden" id="subhidden" />
<table>
    <tr>
        <td valign="top" style="width: 300px;">
            <div id="studentcourses">
                @foreach (var item in Model.allSubject)
                {
                    <h3>
                        @item.name (@item.neptun.ToUpper())</h3>
                    <div>
                        <a href="#" class="buttonclass" style="color: white;" onclick="manage('@item.neptun');">
                            >>></a>
                    </div>
                }
            </div>
        </td>
        <td valign="top">
            <table>
                <tbody>
                    <tr>
                        <td>
                            <input type="text" id="addt" style="display: none;" />
                            <a href="#" id="addtb" class="buttonclass" style="color: white; display: none;" onclick="addtea();">
                                Hozzáadás</a>
                        </td>
                    </tr>
                    <tr>
                        <td>
                        </td>
                    </tr>
                    <tr id="hwcontainer">
                    </tr>
                </tbody>
            </table>
        </td>
    </tr>
</table>
